package org.sjs.dreamfly.model.ixigua

import org.sjs.dreamfly.model.Cover
import org.sjs.dreamfly.model.MovieInfo

data class Album(
    var actorList: List<Any>?,
    var albumGroupId: String?,
    var albumId: String?,
    var albumTypeList: List<Int>?,
    var areaList: List<String>?,
//    var attribute: String?,
//    var bottomLabel: String?,
//    var celebrityList: List<Actor>?,
    var coverList: List<Cover>?,
//    var diggCount: String?,
    var directorList: List<Any>?,
    var duration: String?,
//    var favoriteCount: String?,
//    var groupSource: Int?,
    var intro: String?,
    var label: Label?,
//    var latestSeq: Int?,
//    var logPb: String?,
//    var operationType: Int?,
//    var previews: Previews?,
    var releaseStatus: Int?,
//    var scriptwriterList: List<Actor>?,
//    var searchTagList: List<SearchTag>?,
//    var seqType: Int?,
    var shareUrl: String?,
    var subTitle: String?,
//    var tagInfoList: List<TagInfo>?,
    var tagList: List<String>?,
    var title: String?,
    var totalEpisodes: Int?,
//    var toutiaoLvideoText: String?,
//    var userInfo: UserInfo?,
//    var vipControl: VipControl?,
    var year: String?
) {
    fun toMovieInfo(): MovieInfo {
        return MovieInfo(
            id = albumId?:"",
            name = title,
            refer = this.shareUrl,
            channel = "",
            totalVideoCount = totalEpisodes?:0,
            imageUrl = getImage(),
            coverList = this.coverList,
            introduction = intro,
            subTitle = this.subTitle,
            region = this.areaList.toString().removePrefix("[").removeSuffix("]"),
            year = this.year,
            category = this.tagList.toString().removePrefix("[").removeSuffix("]"),
            actors = extraNames(actorList),
//            actorsList = actorsList,
            direct = extraNames(directorList),
//            directorList = directorList,
            language = null,
            score = null,
            rawData = null,
            host = null,
        )
    }

    private fun extraNames(originList: List<Any>?): String {
        var result = ""
        if (originList?.toTypedArray()?.firstOrNull() is String) {
            result = originList.toString().removePrefix("[").removeSuffix("]")
        } else if (originList?.toTypedArray()?.firstOrNull() is Map<*, *>) {
            originList.forEach {
                (it as Map<*, *>)["name"]?.let { name ->
                    result += "$name,"
                }
            }
            result = result.removeSuffix(",")
        }
        return result
    }

    private fun getImage(): String? {
        return this.coverList?.firstOrNull { it.imageStyle == 2 }?.largeUrlList?.firstOrNull()
    }
}